import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layout/index'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: Layout,
    meta: { title: '首页', icon: 'undeclare' },
    children: [
      {
        path: '',
        meta: { title: '首页' },
        name: 'home',
        component: () => import(/* webpackChunkName: "home" */ '@/views/home.vue')
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import(/* webpackChunkName: "404" */ '@/views/login')
  },
  {
    path: '*',
    name: '404',
    hidden: true,
    component: () => import(/* webpackChunkName: "404" */ '@/views/404.vue')
  }
]

const createRouter = () =>
  new VueRouter({
    mode: 'hash', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: routes
  })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
